package com.gu.qqdemo;

import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.TextView;

import com.gu.qqdemo.frg.MainActityFragment;
import com.gu.qqdemo.utils.LogUtils;
import com.gu.qqdemo.utils.app.BaseActivity;

public class MainActivity extends BaseActivity {
    private DrawerLayout dl;
    private MainActityFragment frag_main;
    private TextView tv_drawer;
    private int Widthdrawer;

    @Override
    protected int getLayoutId() {
        return R.layout.act_main;
    }

    @Override
    protected void initView() {
        dl = findViewById(R.id.dl);
        tv_drawer = findViewById(R.id.tv_drawer);
        frag_main = (MainActityFragment) getSupportFragmentManager().findFragmentById(R.id.frag_main);


        tv_drawer.post(new Runnable() {
            @Override
            public void run() {
                //获取frag_main的全宽
                Widthdrawer = tv_drawer.getMeasuredWidth();
                LogUtils.d("Widthdrawer" + Widthdrawer);
            }
        });
    }

    @Override
    protected void initData() {


        dl.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                //frag_main跟随抽屉滑动
                frag_main.getView().setTranslationX(Widthdrawer * slideOffset);
                //tv_drawer从中间开始滑动
                tv_drawer.setTranslationX(Widthdrawer / 2 - Widthdrawer / 2 * slideOffset);
            }
        });


    }

    @Override
    protected void initListener() {

    }
}
